$(document).ready(function(e) {	

//property1 address null, use home address
var s=$('#property1address').text(); s=s.replace(/\s/g, '');
if(s=="" && $('#p1value').text()!=""){
	var h= $("#homeaddress1").text();
	$('#property1address').text(h); 
}

//set status colors
$("td:contains('Pass'), h2:contains('Pass')").css("color", "green");
$("td:contains('Support Required'), h2:contains('Support Required')").css("color", "red");
$("td:contains('Manual Respond'), h2:contains('Manual Respond')").css("color", "orange");

//estimated loan amount
if($('#ela').text()=="") $('#ela').text('N/A');

//show personal or business table
if($('#purposeSummary').text()=="Personal") $('#bizTable').hide();
if($('#purposeSummary').text()=="Business"){ $('#personalTable').hide(); $(".hideifbiz").hide(); $(".hideifbiz2").css("visibility", "hidden");  }

//alert ($('#p1value').text());
if($('#p1value').text()=="") {$('#propertyTable').hide(); $('#propertyTable').prev('h3').hide(); $('#property12').hide(); }
if($('#p2value').text()=="") $('.p2').hide();
if($('#p3value').text()=="") {$('.p3').hide(); $('#property34').hide();}
if($('#p4value').text()=="") $('.p4').hide();
if($('#p5value').text()=="") {$('.p5').hide(); $('#property56').hide();}
if($('#p6value').text()=="") $('.p6').hide();

if($('#v1value').text()=="") $('.v1').hide();
if($('#v2value').text()=="") $('.v2').hide();
if($('#v3value').text()=="") $('.v3').hide();
if($('#v4value').text()=="") $('.v4').hide();
if($('#b1value').text()=="") $('.b1').hide();

// line through
if($('#HomeOwner').text()=="Not owned") $('.p1').css("text-decoration","line-through");
if($('#InvestmentOwner').text()=="Not owned") $('.p2').css("text-decoration","line-through");
if($('#Property3Owner').text()=="Not owned") $('.p3').css("text-decoration","line-through"); 
if($('#Property4Owner').text()=="Not owned") $('.p4').css("text-decoration","line-through");
if($('#Property5Owner').text()=="Not owned") $('.p5').css("text-decoration","line-through"); 
if($('#Property6Owner').text()=="Not owned") $('.p6').css("text-decoration","line-through");

if($('#Vehicle1Owner').text()=="Not owned") $('.v1').css("text-decoration","line-through");
if($('#Vehicle2Owner').text()=="Not owned") $('.v2').css("text-decoration","line-through");
if($('#Vehicle3Owner').text()=="Not owned") $('.v3').css("text-decoration","line-through");
if($('#Vehicle4Owner').text()=="Not owned") $('.v4').css("text-decoration","line-through");
if($('#BikeOwner1').text()=="Not owned") $('.b1').css("text-decoration","line-through");


if($('#v1value').text()=="" && $('#b1value').text()==""){ $('#vehicleTable').hide(); $('#vehicleTable').prev('h3').hide(); }

/*if($('#personalLoan').text()=="") $('.personalLoan').hide();
if($('#creditCard').text()=="") $('.creditCard').hide();
if($('#paydayLoan').text()=="") $('.paydayLoan').hide();

if($('#otherloan1').text()=="") $('#otherloan1row').hide();
if($('#otherloan2').text()=="") $('#otherloan2row').hide();
if($('#otherloan3').text()=="") $('#otherloan3row').hide();
if($('#otherloan4').text()=="") $('#otherloan4row').hide();*/

//employment details show/hide
if($("#type1").text()=="" && $("#type2").text()=="") $(".type").hide();
if($("#oyear1").text()=="" && $("#oyear2").text()=="") $(".oyear").hide();
if($("#title1").text()=="" && $("#title2").text()=="") $(".title").hide();
if($("#contact1").text()=="" && $("#contact2").text()=="") $(".contact").hide();
if($("#workphone1").text()=="" && $("#workphone2").text()=="") $(".workphone").hide();
if($("#bname1").text()=="" && $("#bname2").text()=="") $(".bname").hide();
if($("#abn1").text()=="" && $("#abn2").text()=="") $(".abn").hide();
if($("#nature1").text()=="" && $("#nature2").text()=="") $(".nature").hide();
if($("#address1").text()=="" && $("#address2").text()=="") $(".address").hide();
if($("#year1").text()=="" && $("#year2").text()=="") $(".year").hide();
if($("#money1").text()=="" && $("#money2").text()=="") $(".money").hide();
if($("#fax1").text()=="" && $("#fax2").text()=="") $(".fax").hide();
if($("#director1").text()=="" && $("#director2").text()=="") $(".director").hide();
if($("#workincome1").text()=="" && $("#workincome2").text()=="") $(".workincome").hide();
if($("#om11").text()=="" && $("#om21").text()=="") $(".om1").hide();
if($("#om12").text()=="" && $("#om22").text()=="") $(".om2").hide();
if($("#om31").text()=="" && $("#om41").text()=="") $(".om3").hide();
if($("#om32").text()=="" && $("#om42").text()=="") $(".om4").hide();


if( $("#toe1").text()=="Centrelink" && $("#toe2").text()=="") $('#TypeofEmployment').hide();
if( $("#toe1").text()=="Centrelink" && $("#toe2").text()=="") $('#WorkIncomeAfterTax').hide();
//calculate disposable income
var ti=$('#totalIncome').text(); ti=toNumber(ti); if(ti<2600) $('.ti').css('color','red');
var lp=$('#livingExpenses').text(); lp=toNumber(lp);
var llp=$('#lowestlivingExpenses').text(); llp=toNumber(llp);
var tp=$('#totalPayment').text(); tp=toNumber(tp);
var brfee=$('#boardingrentingfee').text(); brfee=toNumber(brfee);
if(lp>=llp){
	var di=ti-lp-tp-brfee;
	$('.lowestlivingExpenses').css("text-decoration","line-through");
	$('.te').text('$'+(lp+tp+brfee));
}
else{
	var di=ti-llp-tp-brfee;
	$('.livingExpenses').css("text-decoration","line-through");
	$('.te').text('$'+(llp+tp+brfee));
}
$('.di').text('$'+di); if(di<550) $('.di').css('color','red');



var s=$('#workincomeTd').text(); s=s.replace(/\s/g, '');
if(s=="") $('#workincomeTd').text(0);

var s=$('#centrelinkTd').text(); s=s.replace(/\s/g, '');
if(s=="") $('#centrelinkTd').text(0);

var s=$('#otherincomeTd').text(); s=s.replace(/\s/g, '');
if(s=="") $('#otherincomeTd').text(0);

if($('#boardingrentingfee').text()=="")$('#boardingrentingfee').text('0');
if($('#totalpaymentTd').text()=="")$('#totalpaymentTd').text('0');



//show or hide joint applicant alert
if($('#filledForm').text()=="Yes")
	$('#jointApplicantName').show();
else
	$('#jointApplicantName').hide();

})


var str=$('#purposeDetail').text();
str=str.toLowerCase()
str=str.charAt(0).toUpperCase() + str.slice(1);
$('#purposeDetail').text(str);

$('#afterpage').click(function(e) {
    var url=$(this).text();// alert (url);
	window.open(url);
});

var dob1 = $('#DOB1').text(); 
var year1 = dob1.substr(6, 4);
$('#Age1').text(2013 - year1);

var dob2 = $('#DOB2').text();
var year2 = dob2.substr(6, 4);
if($('#DOB2').text() == "") $("#Age2Hide").hide();
if($('#DOB2').text() != "") $('#Age2').text(2013 - year2);


function opengooglemap(address){
	//alert (address);	
	window.open("http://maps.google.com/maps?hl=en&saddr="+address);
}

function investsmart(h){
	if(h=="home1")
		window.open($("#home1string").text());
	else
		window.open($("#home2string").text());
	
}

$(function(){
	$("#dNav").click(function(e) {
        $.scrollTo('#dTitle',500);
    });
	$("#aNav").click(function(e) {
        $.scrollTo('#aTitle',500);
    });
	$("#cNav").click(function(e) {
        $.scrollTo('#cTitle',500);
    });
	$("#backtotop").click(function(e) {
        $.scrollTo('#pagetop',500);
    });
	$("#usbNav").click(function(e) {
        $.scrollTo('#bizdetail',500);
    });
})

function toNumber(str){
	if(str=="")
		str=0;
	else{
		str=str.replace(/\,/g,'');
		str=parseInt(str);
	}
	return str;	
}
function agtcheck(){
	var agt=$("#agt").text();
	window.open("http://user-agent-string.info/?Fuas="+agt+"&test=9968&action=analyze' target='_blank'")
	
}
function pf(address, suburb, state){
	//alert (address); alert(suburb); alert (state);
	var s=address.split(" ");
	if(s.length>=3){
		var streetNo = s[0];
		var street = s[1]+" "+s[2];
	}
	else{
		var streetNo = "";
		var street = s[0]+" "+s[1];
	}
	
	var postCode="";
	var url="http://www.morganfinance.com.au/PriceFinder/test2.php?streetNo="+streetNo+"&street="+street+"&suburb="+suburb+"&state="+state+"&postCode="+postCode;
	
	//alert (url);
	window.open(url);
}